<?php
/**
 * Sharing World table class
 * 
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4
 * @license		GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * Sharing Table class
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class TableSharing extends JTable
{
	/**
	 * Primary Key
	 *
	 * @var int
	 */
	var $id = null;

	/**
	 * @var string
	 */
	var $date = null;
	var $group = null;
	var $time = null;
	var $end = null;
	var $user = null;

	/**
	 * Constructor
	 *
	 * @param object Database connector object
	 */
	function TableSharing(& $db) {
		parent::__construct('#__sharing', 'id', $db);
	}
	
	function check() {
		if (trim($this->date) == '') {
	      $this->setError(JText::_('Please enter date'));
	      return false;
	    }
	    $d = explode('/', $this->date);
	    if(count($d) != 3 || checkdate($d[1], $d[0], $d[2]) === false) {
	      $this->setError(JText::_('The date is not a valid date format'));
	      return false;
	    }
	    
		if ($this->end <= $this->time)
		{
			$this->setError(JText::_('End time should be bigger than start time'));
			return false;
		}
		
		$this->date = mktime(0,0,0,$d[1],$d[0],$d[2]);
		
		return true;
	}	
}